name: Bot Build

on:
  workflow_dispatch:
  pull_request:
    paths:
      - .github/workflows/bot.yml
      - bot/**

jobs:
  build:
    runs-on: ubuntu-latest
    name: Build
    permissions:
      packages: write
      pull-requests: write

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          cache: maven

      - name: maven build
        run: mvn -pl bot -am package

      - id: jacoco
        uses: madrapps/jacoco-report@v1.6.1
        if: ( github.event_name != 'workflow_dispatch' )
        with:
          paths: ${{ github.workspace }}/bot/target/site/jacoco/jacoco.xml
          token: ${{ secrets.GITHUB_TOKEN }}
          min-coverage-overall: 30
          min-coverage-changed-files: 30
          title: Code Coverage
          update-comment: true

  checkstyle:
    name: checkstyle
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          cache: maven

      - run: mvn -pl bot -am checkstyle:check

  integration-test:
    name: integration tests
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-java@v4
        with:
          java-version: '21'
          distribution: 'temurin'
          cache: maven

      - run: mvn -pl bot -am verify -Dskip.unit.tests=true
